package com.example.mapper;

import com.example.pojo.bo.ClickBO;
import com.example.pojo.bo.HomeCompanyBO;
import com.example.pojo.bo.HomePosterBO;
import com.example.pojo.dto.PostDTO;
import com.example.pojo.entity.Post;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

/**
 * 本文来演示:
 *
 * @author 赵建云
 * @create 2023/9/29
 */
public interface PostMapper {
    @Select("select id,jr_id,pos_name,pos_type,pay_floor,pay_upper,background from post")
    List<HomePosterBO> findAll();
    @Select("select * from post where jr_id = #{value}")
    List<Post> findAllPost(Integer jrId);

    @Select("select * from post")
    List<Post> findAlls();
    @Insert("insert into post(jr_id,pos_name,pos_type,pos_description,pos_keyword,work_place,recruits_num,pay_floor,pay_upper,background,specialty,sex_demand,exp_demand,age_demand,job_benefits,recruitment_agency,pos_telephone,pos_email,publish_status,publish_cycle) values(#{jrId},#{posName},#{posType},#{posDescription},#{posKeyword},#{workPlace},#{recruitsNum},#{payFloor},#{payUpper},#{background},#{specialty},#{sexDemand},#{expDemand},#{ageDemand},#{jobBenefits},#{recruitmentAgency},#{posTelephone},#{posEmail},#{publishStatus},#{publishCycle}) ")
    int save(PostDTO postDTO);
    @Update("update post set pos_name=#{posName},pos_type=#{posType},pos_description=#{posDescription},pos_keyword=#{posKeyword},work_place=#{workPlace},recruits_num=#{recruitsNum},pay_floor=#{payFloor},pay_upper=#{payUpper},background=#{background},specialty=#{specialty},sex_demand=#{sexDemand},exp_demand=#{expDemand},age_demand=#{ageDemand},job_benefits=#{jobBenefits},recruitment_agency=#{recruitmentAgency},pos_telephone=#{posTelephone},pos_email=#{posEmail},publish_status=#{publishStatus},publish_cycle=#{publishCycle} where id = #{id} and jr_id=#{jrId}")
    int update(PostDTO postDTO);
    @Select("select pos_name,pay_floor,pay_upper from post where jr_id = #{value} order by recruits_num desc limit 1")
    HomePosterBO findById(Integer jrId);

    @Select("select * from post where id=#{value}")
    Post findAllByPostId(Integer id);


    @Delete("delete from post where id=#{id} and jr_id=#{jrId}")
    int delByJrId(@Param("id") Integer Id,@Param("jrId") Integer jrId);

//    @Select("select * from post where pos_name like concat('%',#{posName},'%') and jr_id=#{jrId}")
//    List<Post> findByPosName(@Param("posName") String posName,@Param("jrId") Integer jirId);
    List<Post> findByPosName(@Param("posName")String posName, @Param("jrId")Integer jirId);





    @Select("select * from post where jr_id=#{value}")
    List<Post> findByJrId(Integer jrId);


    @Select("select jr_id from post where pos_name like concat('%',#{value},'%')")
    Set<Integer> findByPosition(String position);
    
    @Select("select count(*) from post where jr_id =#{value} ")
    int contByJrId(Integer jrId);

    @Delete("delete from post where id=#{value}")
    int delById(Integer id);

    @Select("select pos_type,pos_keyword from post where id=#{value}")
    ClickBO clickSave(Integer posId);

    @Select("select id,jr_id,pos_name,pos_type,pay_floor,pay_upper,background from post where id=#{value}")
    HomePosterBO findByPosId(Integer id);

    @Update("update post set pos_hits=pos_hits+#{pH} where id=#{id}")
    int updates(@Param("pH") Integer pH,@Param("id") Integer id);

    @Select("select * from post order by pos_hits desc ")//limit 5
    List<Post> limitPost();

}
